﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 逻辑
{
    public class 车:QiZi
    {
        public 车(int x, int y, QiPan q, Button[,] b, int p)
            : base("车", x, y, q, p, b)
        {
        }

        public override void CanPut()
        {
            canPut.Clear();
            int x1 = x;
            while(true)
            {
                x1++;
                if (x1 > 9)
                    break;
                if(buttons[x1,y].Tag == null)
                {
                    int z = Game.ChangeDirection(this.Player,x1);
                    canPut.Add(z * 10 + y);
                }
                else if ((buttons[x1, y].Tag as QiZi).Player != this.Player)
                {
                    int z = Game.ChangeDirection(this.Player, x1);
                    canPut.Add(z * 10 + y);
                    break;
                }
                else
                {
                    break;
                }
            }
            x1 = x;
            while (true)
            {
                x1--;
                if (x1 <0)
                    break;
                if (buttons[x1, y].Tag == null)
                {
                    int z = Game.ChangeDirection(this.Player, x1);
                    canPut.Add(z * 10 + y);
                }
                else if ((buttons[x1, y].Tag as QiZi).Player != this.Player)
                {
                    int z = Game.ChangeDirection(this.Player, x1);
                    canPut.Add(z * 10 + y);
                    break;
                }
                else
                {
                    break;
                }
            }
            x1 = y;
            while (true)
            {
                x1++;
                if (x1 > 8)
                    break;
                if (buttons[x, x1].Tag == null)
                {
                    int z = Game.ChangeDirection(this.Player, x);
                    canPut.Add(z * 10 + x1);
                }
                else if ((buttons[x, x1].Tag as QiZi).Player != this.Player)
                {
                    int z = Game.ChangeDirection(this.Player, x);
                    canPut.Add(z * 10 + x1);
                    break;
                }
                else
                {
                    break;
                }
            }
            x1 = y;
            while (true)
            {
                x1--;
                if (x1 < 0)
                    break;
                if (buttons[x, x1].Tag == null)
                {
                    int z = Game.ChangeDirection(this.Player, x);
                    canPut.Add(z * 10 + x1);
                }
                else if ((buttons[x, x1].Tag as QiZi).Player != this.Player)
                {
                    int z = Game.ChangeDirection(this.Player, x);
                    canPut.Add(z * 10 + x1);
                    break;
                }
                else
                {
                    break;
                }
            }
        }

    }
}
